package com.qiangqiang.task.server.ranking;

import com.qiangqiang.task.server.ranking.entity.RankingUser;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;

/**
 * @program: task
 * @description:
 * @author: Sky.lin
 * @create: 2019-02-12 22:22
 **/
public class Comparators {
    public static Comparator getComparator() {
        return (r1, r2) -> compareUser((RankingUser) r1, (RankingUser) r2);
    }


    /**
     * @Description: 定义比较规则：用户成就值降序排序，相同则按照用户创建时间升序排序
     * @Param:
     * @return:
     * @Author: sky.lin
     * @Date: 2019/2/12
     */
    public static int compareUser(RankingUser r1, RankingUser r2) {
        if (r1.getAchievement() != r2.getAchievement())
            return r2.getAchievement() - r1.getAchievement();
        else if (r1.getUserId() > r2.getUserId())
            return 1;
        else if (r1.getUserId() == r2.getUserId())
            return 0;
        else
            return -1;
    }
}
